package com.tdam2011.grupo05.control.notification;

import com.tdam2011.grupo05.R;
import com.tdam2011.grupo05.ui.activities.message.MessageWebActivity;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

public class NotificationMessage extends AbstractNotification {

	private static final int NEW_MESSAGE = 1;
	private static final int MESSAGE_FAIL = 3;

	public static void notifyNewMessageInbox(Context context, String t,
			String m, int id) {
		Notification notification = getNotification(context, NEW_MESSAGE, t, m);
		getManager(context).notify(id, notification);
	}

	public static void notifyMessageFail(Context context, String t, String m,
			int id) {
		Notification notification = getNotification(context, MESSAGE_FAIL, t, m);
		getManager(context).notify(id, notification);
	}

	private static Notification getNotification(Context context, int option,
			String title, String message) {
		Notification notification = null;
		PendingIntent pIntent = null;
		Intent intent = new Intent();
		intent.setComponent(new ComponentName(context.getPackageName(),
				MessageWebActivity.class.getName()));
		switch (option) {
		case NEW_MESSAGE:
			notification = new Notification(
					R.drawable.ic_sms_log_list_incoming_sms, message,
					System.currentTimeMillis());
			pIntent = PendingIntent.getActivity(context, NEW_MESSAGE, intent,
					PendingIntent.PARCELABLE_WRITE_RETURN_VALUE);
			notification.setLatestEventInfo(context, title, message, pIntent);

			break;
		case MESSAGE_FAIL:
			notification = new Notification(R.drawable.ic_sms_log_list_error,
					message, System.currentTimeMillis());
			pIntent = PendingIntent.getActivity(context, 0, intent,
					PendingIntent.PARCELABLE_WRITE_RETURN_VALUE);
			notification.setLatestEventInfo(context, title, message, pIntent);

			break;
		default:
			throw new UnknownError("unkown option: " + option);
		}
		notification.flags |= Notification.FLAG_AUTO_CANCEL;
		notification.defaults |= Notification.DEFAULT_SOUND;
		notification.ledARGB |= Notification.FLAG_SHOW_LIGHTS;
		return notification;
	}

}
